package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqGeneralValueResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class VolumeAdjustmentReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;
    @Override
    public String parseMessage(String data) {
        // *WT,866248050395985,V4,SPEAKER,000821,2,095325,A,2250.2256,N,11391.6190,E,0.18,162,030621,FFFFDFFF
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber=split[4];
        String speakLevel=split[5];//(2，1，0) 分别对应大中小,设备已经获取的音量设置
        String deviceTime = split[6];
        String latitude = split[8];
        String longitude = split[10];
        String speed = split[12];
        String orientation = split[13];
        String deviceDate = split[14];
        String deviceStatus = split[15];
        List<Double> list = LocationUtils.transiformLatAndLng(longitude, latitude);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        MqGeneralValueResult mqGeneralValueResult = new MqGeneralValueResult();
        mqGeneralValueResult.setCommandNumber(commandNumber);
        mqGeneralValueResult.setImei(imei);
        mqGeneralValueResult.setDeviceDate(deviceDate);
        mqGeneralValueResult.setDeviceStatus(deviceStatus);
        mqGeneralValueResult.setDeviceTime(deviceTime);
        mqGeneralValueResult.setMqLocationData(mqLocationData);
        mqGeneralValueResult.setValue(speakLevel);
        InjectFeignService.getIrmFeignClientService().volumeAdjustResponse(mqGeneralValueResult);
        return imei;
    }
}
